package com.struts2.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.struts2.model.Color;
import com.struts2.model.Product_item;
import com.struts2.model.Product_line;
import com.struts2.model.Size;
import com.struts2.service.ProductUploadService;
import com.struts2.service.ProductUploadService2;

public class ProductUploadAction2 extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = 1L;
	
	private Product_item productItem;
	private Product_line productLineModel;
	private Color colorModel;
	private Size sizeModel;
	private int productLineId;
	private int sizeCount;
	private int colorCount;
	private int[][] colorsize = new int[100][100];
	
	private Map<String, Object> session;
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	public String uploadProductItem() {
		System.out.println("uploadProductItem called");
		System.out.println(productLineId);
		System.out.println(sizeCount);
		System.out.println(colorCount);
		String pidString = Integer.toString(productLineId);
		session.put("pid", pidString);
		ProductUploadService2 productUploadService2 = new ProductUploadService2();
		productItem = new Product_item();
		productLineModel = productUploadService2.productLineModel(productLineModel, productLineId);
		for(int x = 1; x<sizeCount; x++){
			for(int y = 1; y<colorCount; y++){
				if(colorsize[x][y] != 0){
					colorModel = productUploadService2.colorModel(colorModel, y);
					sizeModel = productUploadService2.sizeModel(sizeModel, x);
					productItem = productUploadService2.insert(productItem, productLineModel, colorModel, sizeModel, colorsize[x][y]);
				}
			}
		}
		return SUCCESS;
	}

	public int[][] getColorsize() {
		return colorsize;
	}
	public void setColorsize(int[][] colorsize) {
		this.colorsize = colorsize;
	}
	public int getSizeCount() {
		return sizeCount;
	}
	public void setSizeCount(int sizeCount) {
		this.sizeCount = sizeCount;
	}
	public int getColorCount() {
		return colorCount;
	}
	public void setColorCount(int colorCount) {
		this.colorCount = colorCount;
	}

	public int getProductLineId() {
		return productLineId;
	}

	public void setProductLineId(int productLineId) {
		this.productLineId = productLineId;
	}
}
